package main;

import javax.swing.*;
import javax.swing.text.Highlighter;
import javax.swing.text.DefaultHighlighter;
import java.awt.*;

public class CSExchangeImpl implements CSExchange {
    public static final Color DEFAULT_COLOR= Color.blue;

    JEditorPane edit;
    
    public CSExchangeImpl(JEditorPane edit) {
        this.edit=edit;
    }
    public JEditorPane getEditor() {
        return edit;
    }
    public HighlightInfo[] getHighlights() {
        HighlightInfo[] res=new HighlightInfo[edit.getHighlighter().getHighlights().length];
        Color c;
        for (int i=0; i<res.length; i++) {
            c=DEFAULT_COLOR;
            Highlighter.Highlight h=edit.getHighlighter().getHighlights()[i];
            if (h.getPainter() instanceof DefaultHighlighter.DefaultHighlightPainter) {
                DefaultHighlighter.DefaultHighlightPainter p=(DefaultHighlighter.DefaultHighlightPainter)h.getPainter();
                c=p.getColor();
            }
            res[i]=new HighlightInfoImpl(h.getStartOffset(), h.getEndOffset(), c);
        }
        
        return res;
    }
}
